package com.spzx.order.receiver;


import com.rabbitmq.client.Channel;
import com.spzx.rabbit.constant.MqConst;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class TestReceiver {

    // 使用注解绑定队列和交换机
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange(value = MqConst.EXCHANGE_TEST, durable = "true"),
            value = @Queue(value = MqConst.QUEUE_TEST, durable = "true"),
            key = {MqConst.ROUTING_TEST}
    ))

    public void a(Channel channel, Message message, String msg) throws Exception{
        byte[] body = message.getBody();
        String bodyStr = new String(body);
        System.out.println(bodyStr);
        System.out.println(msg);
        // 默认自动应答
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false); // 手动应答， 非批量确认
    }
}
